<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>这是一个测试jsp</title>
    <script src="js/jquery.min.js"></script>
    <script src="js/echarts.min.js"></script>
</head>
<body>
<!-- 为ECharts准备一个具备大小（宽高）的Dom -->
<div id="tu1" style="width:1400px;height:660px;">

</div>
<%--<h1 style="color: aliceblue">租车数量排名前十的时间点</h1>--%>
<%--<div id="tu2" style="width: 600px;height:400px;"></div>--%>
<script type="text/javascript">
    // 基于准备好的dom，初始化echarts实例
    var myChart = echarts.init(document.getElementById('tu1'));
    // 指定图表的配置项和数据

    option = {
        title: {
            text: "租车数量排名前十的时间点",
            left: 'center',
            padding: 10,
            textStyle: {
                fontFamily:"FZYingBiKaiShu-S15S",
                color: '#ffffff',
                fontSize:30
            }
        },
        grid: {
            left: '5%',
            right: '5%',
            bottom: '5%',
            top: '10%',
            containLabel: true
        },
        tooltip: {
            trigger: 'axis',
            axisPointer: {
                type: 'none'
            },
            formatter: function (params) {
                return params[0].name + '<br/>' +
                    "<span style='display:inline-block;margin-right:5px;border-radius:10px;width:9px;height:9px;background-color:rgba(36,207,233,0.9)'></span>" +
                    params[0].seriesName + ' : ' + Number((params[0].value.toFixed(4) / 10000).toFixed(2)).toLocaleString() + ' 万元<br/>'
            }
        },
        backgroundColor: 'rgb(20,28,52)',
        xAxis: {
            show: false,
            type: 'value'
        },
        yAxis: [{
            type: 'category',
            inverse: true,
            axisLabel: {
                show: true,
                textStyle: {
                    color: '#fff'
                },
            },
            splitLine: {
                show: false
            },
            axisTick: {
                show: false
            },
            axisLine: {
                show: false
            },
            data: []
        }, {
            type: 'category',
            inverse: true,
            axisTick: 'none',
            axisLine: 'none',
            show: true,
            axisLabel: {
                textStyle: {
                    color: '#ffffff',
                    fontSize: '12'
                },
                formatter: function (value) {
                    if (value >= 10000) {
                        return (value / 10000).toLocaleString() + '万';
                    } else {
                        return value.toLocaleString();
                    }
                },
            },
            data: []
        }],
        series: [{
            name: '金额',
            type: 'bar',
            zlevel: 1,
            itemStyle: {
                normal: {
                    barBorderRadius: 30,
                    color: new echarts.graphic.LinearGradient(0, 0, 1, 0, [{
                        offset: 0,
                        color: 'rgb(57,89,255,1)'
                    }, {
                        offset: 1,
                        color: 'rgb(46,200,207,1)'
                    }]),
                },
            },
            barWidth: 20,
            data: []
        },
            {
                name: '背景',
                type: 'bar',
                barWidth: 20,
                barGap: '-100%',
                data: [],
                itemStyle: {
                    normal: {
                        color: 'rgba(24,31,68,1)',
                        barBorderRadius: 30,
                    }
                },
            },
        ]
    };
    var hours = [];  //存放从后台传来的数据--日期
    var counts = [];  //温度
    // 页面加载完毕之后，通过ajax加载图标的数据
    $.ajax({
        url: 'hss',
        method: "get",
        dataType: "json",
        success: function (data) {
            alert(JSON.stringify(data));  //测试ajax是否成功调用了servlet
            if (data) {
                for (var i = 0; i < data.length; i++) { //把servlet传来的data存放到新定义的数组中
                    hours.push(data[i]['hour'] + '点');      //data[i]['yueFen'] 'yuefen'与bean中的toString()方法名称一致
                }
                for (var i = 0; i < data.length; i++) {
                    counts.push(data[i]['count']);
                }
                myChart.setOption({
                    yAxis: [{
                        data: hours
                    }, {
                        data: counts
                    }],
                    series: [{
                        data: counts
                    }, {
                        data: counts
                    }]


                })
            }

        },
        error: function (errMsg) {
            console.error(errMsg)
        }

    });
    myChart.setOption(option);

</script>


</body>
</html>
